﻿
// 2023/2/28: 首个版本
// 2023/7/19: 支持存储H264/H265码流至MKV (需要ffmpegdl 1.8)
// 2023/8/24: 修正mp4和mkv读取
// 2023/8/25: 修正getH264ExtradataSize
// 2023/8/29: 移除dtsFromOne
// 2023/8/29: 解决mkv文件dts问题
// 2023/10/9: 添加英文注释
// 2024/6/12: 支持spadas9

#ifndef _NEXT_FILE_IO_H__
#define _NEXT_FILE_IO_H__

#include "spadas.h"

namespace videonext
{
	using namespace spadas;

	// Compatibility / 兼容性:
	// - MJPEG: avi, mp4, mkv
	// - H264: avi, mp4, mkv
	// - H265: avi, mp4, mkv
	// - YUV411: avi, mkv
	// - YUV420: avi, mkv

	// Pixel format : 像素格式:
	// - YUV411: Y41P，for 8 pixels / 每八像素：U0 Y0 V0 Y1 U4 Y2 V4 Y3 Y4 Y5 Y6 Y7
	// - YUV420: YUV4，for 2x2 pixels / 每2x2像素：U V Y00 Y01 Y10 Y11

	struct FileFormat
	{
		Enum<VideoDataCodec> codec;
		UInt width;
		UInt height;
		UInt fps;

		FileFormat() : codec(VideoDataCodec::Value::Invalid), width(0), height(0), fps(0)
		{}
	};

	class FileReader : public Object<class FileReaderVars>
	{
	public:
		FileReader();
		Bool open(Path filePath, FileFormat& format);
		Bool seek(UInt frameIndex, Bool any);
		Bool readFrame(Binary& frame, UInt *frameIndex = NULL);
		void close();
		static Bool peekFormat(Path filePath, FileFormat& format);
	};

	class FileWriter : public Object<class FileWriterVars>
	{
	public:
		FileWriter();
		Bool open(Path filePath, FileFormat format);
		UInt writeFrame(Binary frame);
		void close();
	};
}

#endif
